//导入父类
import defaultConfig from './default-option'

export default class OptionRadar extends defaultConfig {
  constructor({ rows = [], columns = [], header = columns[0] }, settings = {}, extend = {}) {
    super()
    const keyArr = columns.filter(item => item !== header)
    this.option = this.defaultConfig
    this.option = this.setNewStyle({
      radar: {
        shape: 'circle',
        indicator: keyArr.map(item => ({ name: item }))
      }
    }, this.option)
    this.option.series =
      [{
        name: header,
        type: 'radar',
        data: rows.map(item => ({ name: item[header], value: keyArr.map(list => item[list]) }))
      }]
    this.mySettings(this.option, settings)
    this.option = this.setNewStyle(extend, this.option)
  }
  mySettings = (option, settings) => {
    this.hiddenXY(option)
    this.deleteType(option)
    this.thisDefaultConfig(option, {
      tooltip: {
        trigger: 'item',
      }
    })
    if (settings.label) {
      const { label } = settings
      this.setLabel(option, label)
    }
    if (settings.updateLabel) {
      const { updateLabel } = settings
      this.setUpdateLabel(option, updateLabel)
    }
  }
  //删除特殊值
  deleteType(option) {
    delete option.xAxis
    delete option.yAxis
    delete option.dataZoom
  }
  setLabel = (option, label) => {
    option.series.forEach(item => this.setNewStyle({ label }, item))
  }
  setUpdateLabel = (option, updateLabel) => {

    option.radar.indicator.forEach(item => {
      item.name = updateLabel[item.name]
    })
  }

}